var t = getApp();

Component({
    options: {
        styleIsolation: "shared"
    },
    properties: {
        homeIsShow: {
            type: Boolean,
            value: !1
        },
        goodsIsShow: {
            type: Boolean,
            value: !0
        },
        allDataList: {
            type: null,
            value: {}
        },
        activeIndex: {
            type: null,
            value: 0
        }
    },
    data: {
        currentIndex: 1,
        total: 3,
        bubbleData: [],
        posterShow: !1,
        posterImg: "",
        isMoreNum: !1
    },
    observers: {
        activeIndex: function(t) {
            this.data.homeIsShow || (clearInterval(this.data.timer), this.setData({
                bubbleData: []
            }), this.initScatter());
        }
    },
    lifetimes: {
        attached: function() {
            clearInterval(this.data.timer), this.initScatter();
        }
    },
    methods: {
        initScatter: function() {
            var t = this;
            if (this.data.allDataList.list) {
                var e = this.data.allDataList.list[this.data.activeIndex] ? this.data.allDataList.list[this.data.activeIndex].goods : [], a = [ 100, 220, 10, 320, 170 ];
                e.forEach(function(t, e) {
                    t.top = "250rpx", t.left = 1 * a[e % 5] + 160 + "rpx", t.width = 120, t.time = 5;
                });
                var i = 0;
                this.setData({
                    isMoreNum: e.length < 5
                });
                var o = [];
                clearInterval(this.data.timer), this.data.timer = setInterval(function() {
                    if (t.data.isMoreNum && i >= e.length) return i = 0, void clearInterval(t.data.timer);
                    i >= e.length && (i = 0), o.push(e[i]), t.setData({
                        bubbleData: o
                    }), ++i;
                }, 1e3);
            }
        },
        clickCheck: function() {
            wx.navigateTo({
                url: "/packageF/new_blind_box/blindPool/index?id=" + this.data.allDataList.list[this.data.activeIndex].id
            });
        },
        openService: function() {
            this.setData({
                showServicePopup: !this.data.showServicePopup
            });
        },
        goToMyBindBox: function() {
            wx.navigateTo({
                url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=newBindBox&title=我的盲盒"
            });
        },
        postShow: function() {
            var e = this;
            t._getNetWork({
                url: t.getNetAddresss("plugin.new-blind-box.frontend.index.poster"),
                data: {
                    id: this.data.allDataList.list[this.data.activeIndex].id
                },
                success: function(t) {
                    var a = t.data;
                    a.result ? e.setData({
                        posterImg: a.data.poster,
                        posterShow: !0
                    }) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        },
        shareHint: function() {
            wx.showToast({
                icon: "none",
                title: "长按图片分享好友",
                duration: 3e3
            });
        },
        saveImg: function() {
            wx.getSetting({
                success: function(t) {
                    t.authSetting["scope.writePhotosAlbum"] || wx.authorize({
                        scope: "scope.writePhotosAlbum",
                        success: function() {
                            console.log("授权成功");
                        }
                    });
                }
            });
            var t = this.data.posterImg;
            wx.downloadFile({
                url: t,
                success: function(t) {
                    wx.saveImageToPhotosAlbum({
                        filePath: t.tempFilePath,
                        success: function(t) {
                            wx.showToast({
                                title: "保存成功",
                                icon: "none",
                                duration: 2e3
                            });
                        },
                        fail: function(t) {
                            "saveImageToPhotosAlbum:fail auth deny" === t.errMsg && (console.log("当初用户拒绝，再次发起授权"), 
                            wx.openSetting({
                                success: function(t) {
                                    t.authSetting["scope.writePhotosAlbum"] ? wx.showToast({
                                        icon: "none",
                                        title: "获取权限成功,再次长按保存图片",
                                        duration: 1500
                                    }) : wx.showToast({
                                        icon: "none",
                                        title: "获取权限失败,保存图片需要用户授权",
                                        duration: 1500
                                    });
                                }
                            }));
                        },
                        complete: function(t) {
                            console.log(t);
                        }
                    });
                }
            });
        },
        closePoster: function() {
            this.setData({
                posterShow: !1
            });
        },
        goHomePage: function() {
            clearInterval(this.data.timer), wx.navigateTo({
                url: "/packageF/new_blind_box/index?id=" + this.data.allDataList.list[this.data.activeIndex].id
            });
        }
    }
});